// Settings Page
Ext.define("BioGene.view.SettingsView", {
	extend: "Ext.form.Panel",
	alias: "widget.settingsview",
	
	requires: [
        'Ext.field.Select',
        'Ext.form.FieldSet'
    ],
	
	config: {
		scrollable: true,
    	id:'settingsform',
    	submitOnAction: false
	},
    
    initialize: function () {
		
		this.callParent(arguments);
		
        var saveButton = new Ext.Button({
            text: 'Save',
            ui: 'normal',
            handler: this.onSaveTap,
            scope: this
        });


		var cancelButton = new Ext.Button({
            text: 'Cancel',
            ui: 'normal',
            handler: this.onCancelTap,
            scope: this
        });


        var topToolbar = new Ext.Toolbar({
            title: 'Settings',
            docked: 'top',
            items: [
            	cancelButton,
            	{ xtype: 'spacer' },
                saveButton
            ]
        });
        
        var organismSelect = {
        	xtype: 'selectfield',
        	name: 'organism',
        	id: 'organismSelect',
        	label: 'Organism',
        	options: [
	            	{text: 'Human',  value: 'human'},
	            	{text: 'Mouse', value: 'mouse'},
	            	{text: 'Rat', value: 'rat'},
	            	{text: 'Zebrafish', value: 'zebrafish'},
	            	{text: 'Fruitfly', value: 'fruitfly'},
	            	{text: 'Nematode', value: 'nematode'},
	            	{text: 'Arabidopsis', value: 'arabidopsis'},
	            	{text: 'Yeast', value: 'yeast'}
	            ],
	        value: getCookie("bg_organism")
        };
        
        var geneSelect = {
        	xtype: 'selectfield',
        	name: 'genes_per_page',
        	id: 'geneSelect',
        	label: 'Results',
        		options: [
	            	{text: '5 Results Per Page',  value: '5'},
	            	{text: '10 Results Per Page',  value: '10'},
	            	{text: '20 Results Per Page',  value: '20'},
	            	{text: '40 Results Per Page',  value: '40'}
	            ],
	            value: getCookie("bg_results")
        };
        
        var rifSelect = {
        	xtype: 'selectfield',
        	name: 'rifs_per_page',
        	id: 'rifSelect',
        	label: 'Results',
        		options: [
	            	{text: '5 Results Per Page',  value: '5'},
	            	{text: '10 Results Per Page',  value: '10'},
	            	{text: '20 Results Per Page',  value: '20'},
	            	{text: '40 Results Per Page',  value: '40'}
	            ],
	            value: getCookie("bg_references")
        };

        this.add([topToolbar, {
        	xtype: 'fieldset',
        	title: 'Search Settings',
        	items: [organismSelect, geneSelect]
        }, {
        	xtype: 'fieldset',
        	title: 'Reference Display Settings',
        	items: [rifSelect]
        }]);

    },

    onSaveTap: function () {
		this.fireEvent("saveSettings", this);
		this.fireEvent("indexReturn", this);
    },
    
    onCancelTap: function () {
		this.fireEvent("indexCancelReturn", this);
    }
    
});